package com.gao.xml.jackson;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.gao.xml.jackson.xml.User;
import org.junit.Test;

/**
 * @author GaoXi
 * @date 2021/8/18 15:28
 */
public class Demo {

    XmlMapper xmlMapper = XmlMapper.builder()
        //  忽略实体类没有对应属性    如果为 true 会抛出异常
        .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false)
        // 忽略null
        .serializationInclusion(JsonInclude.Include.NON_NULL)
        // 属性使用 驼峰首字母小写
        .propertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE)
        .build();

    @Test
    public void test() throws JsonProcessingException {
        User user = new User();
        String s = xmlMapper.writeValueAsString(user);
        System.out.println(s);

    }



}
